home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 18
/
018.d81
/
pps #41
< prev
next >
Wrap
Text File
|
2022-08-26
|
6KB
|
350 lines
======================================
PEEKs, POKEs, and SYSes, Part 41
by Alan Gardner & Jim Weiler
======================================
-----------------
ENVELOPE, or ADSR
-----------------
I hate acronyms. Don't you?
Today's acronym is ADSR. It stands
for Attack/Decay/Sustain/Release.
This is the ONLY time I will use it's
full name, so please read it a couple
times before continuing.
----
An envelope is a way to picture
the volume of any sound as time
passes. Here's a graph of a
hypothetical envelope of rolling
thunder:
v ! ...
o ! . ..
l ! . . ..
u ! . ... ... ..
m !. ........ .....
e +----------------------------------
1 sec 2 sec 3 sec
Every sound has a volume envelope.
Starting from silence, the volume
rises to some peak level and then dies
back to silence.
The envelopes of most natural
sounds are very complicated, but
musical instruments tend to have
simpler envelopes. ADSR was designed
to describe this simpler type of
envelope.
A musical tone will start from
silence and rise quickly to a peak
volume. If the tone is from a wind,
reed, or bowed instrument (flute,
trumpet, violin) the tone will stay
at or near that peak volume as long
as the note is being played. Then it
will gradually die down to silence
again.
If the tone is from a plucked or
struck instrument (guitar, xylophone,
piano) the tone will immediately
drop in volume and remain at that
intermediate volume for a while.
Then it will gradually die down to
silence again.
Of course, real instrument's
envelopes aren't quite this simple,
but you can achieve reasonable
approximations using envelopes much
like these:
organ violin piano
....... ... ..
. . . . . .
. . . . . ....
. . . . . .
. . . . . .
. . . . . .
The organ produces full volume
sound as soon as you press a key and
plays at that level until you release
the key. Then it quickly dies away.
The volume of the violin increases
as you begin to move the bow, holds
near peak volume as you bow it, and
then gradually the strings stop
vibrating after you lift the bow.
The piano produces a loud sound
when the hammer hits the wires, but
the volume quickly dies to a lower
level and stays at about that level
until you release the key. Then the
vibrations of the wire are quickly
damped out.
----
So, how does ADSR relate to all
this talk of instruments and
envelopes? Like this:
ATTACK is the leading edge of the
envelope -- how long it takes the
sound to reach its peak volume. The
attack of an organ is very fast --
the sound builds up immediately.
DECAY begins as soon as the peak
volume is reached. In an instrument
like the organ or violin, where
energy is being continuously pumped
into each note, the volume won't
decay much at all. In the piano, all
the energy was delivered by one blow
of the hammer, and the strings
rapidly lose much of their energy
(energy = sound volume).
SUSTAIN begins where decay leaves
off. This is the equilibrium volume
of the instrument. In an organ, it
would be full volume, because there
is no decay. In a piano, it's the
volume sustained by a note while you
hold the key down. The SID chip's
sustain is a constant level. In real
life, a piano loses volume while in
the sustain part of the waveform. As
I said earlier, these envelopes are
just reasonable approximations of the
real thing.
RELEASE is what happens when the
musician stops playing a note. On an
organ, as soon as you release the key
the volume drops to nothing (except
for reverberations -- they're
something SID can't handle). It has
a very short release. A xylophone,
on the other hand, dies out
gradually. It has a long release
(unless you damp it with your hand.)
--------------------
HOW SID HANDLES ADSR
--------------------
Believe it or not, SID treats ADSR
just like I described it above. The
values for attack, decay, sustain,
and release can range from a minimum
of 0 to a maximum of 15.
Attack time will range from 2
milliseconds to 8 seconds, decay from
6 ms to 24 seconds, and release from
6 ms to 24 seconds. The sustain level
ranges from 0/15 to 15/15 of the
volume.
-------------------------------------
HOW DO YOU TELL SID WHAT ADSR TO USE?
-------------------------------------
You set ADSR for each SID voice
individually by POKEing ADSR values
into two adjacent memory locations as
follows:
A&D S&R
----------
Voice 1: S+5 S+6
Voice 2: S+12 S+13
Voice 3: S+19 S+20
The way you get both attack and
decay or sustain and release into the
same byte is via formulae like these:
AD = A*16+D : SR = S*16+R
POKE S+5,AD : POKE S+6,SR
Now let's look at some examples
that might simulate the envelopes we
drew for the organ, violin, and
piano.
----
ORGAN
Fast attack = 0
No decay = 0
High level sustain = 15
Fast release = 0
AD = 0*16+0 : SR = 15*16+0
POKE S+5,AD : POKE S+6,SR
----
VIOLIN
Moderate attack = 4
Slow decay = 7
High level sustain = 12
Slow release = 7
AD = 4*16+7 : SR = 12*16+7
POKE S+12,AD: POKE S+13,SR
----
PIANO
Moderate attack = 3
Moderate decay = 4
Mid level sustain = 8
Moderate release = 5
AD = 3*16+4 : SR = 8*16+7
POKE S+19,AD: POKE S+20,SR
----
How did I arrive at those particular
values for ADSR? Easy! I just
guessed. The best way to make an
educated guess is to use a tool that
will play a note with any envelope you
design. We supply you with such a
tool: The AWG ADSR TOY. (It's this
month's example program.)
If you want to play around with
designing your own ADSR envelopes,
run this month's sample program by
pressing the "\" key now (the British
\oad"awg adsr toy",8
Pound sign).
---------< end of article >-----------